package com.hong.qrpc.config;

import com.hong.qrpc.TransportClient;
import com.hong.qrpc.TransportSelector;
import com.hong.qrpc.client.NettyTransportClient;
import com.hong.qrpc.codec.Decoder;
import com.hong.qrpc.codec.Encoder;
import com.hong.qrpc.codec.impl.HessianDecoder;
import com.hong.qrpc.codec.impl.HessianEncoder;
import com.hong.qrpc.constant.ProtoTypeConst;
import com.hong.qrpc.selector.RandomTransportSelector;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author HQT
 * @Date 2022/7/10 16:29
 */
@Slf4j
public class RpcClientConfig extends AbstractConfig {
    /**
     * 是否是通过spring启动项目
     */
    private Boolean startBySpring = false;
    /**
     * 传输的服务对象
     */
    private Class<? extends TransportClient> transportClass = NettyTransportClient.class;
    /**
     * 序列化类
     */
    private Class<? extends Encoder> encoderClass = HessianEncoder.class;
    /**
     * 反序列化类
     */
    private Class<? extends Decoder> decoderClass = HessianDecoder.class;
    /**
     * 路由选择
     */
    private Class<? extends TransportSelector> selectorClass = RandomTransportSelector.class;
    /**
     * 默认端口为零(在bind的时候传入0会随机选择一个空闲端口)
     */
    private int port = 0;
    /**
     * 连接数
     */
    private int connectCount = 0;
    /**
     * 协议类型的编号
     */
    private int protocolType = ProtoTypeConst.QRPC;
    /**
     * 此处采用单例模式来确保所有的对象可以同步更新，存放服务器实例，用服务名作为key，服务端点集合作为value
     */
    private Map<String, List<TransportClient>> servers = new HashMap<>();

    public RpcClientConfig() throws IOException {
    }

    public Class<? extends TransportClient> getTransportClass() {
        return transportClass;
    }

    public void setTransportClass(Class<? extends TransportClient> transportClass) {
        this.transportClass = transportClass;
    }

    public Class<? extends Encoder> getEncoderClass() {
        return encoderClass;
    }

    public void setEncoderClass(Class<? extends Encoder> encoderClass) {
        this.encoderClass = encoderClass;
    }

    public Class<? extends Decoder> getDecoderClass() {
        return decoderClass;
    }

    public void setDecoderClass(Class<? extends Decoder> decoderClass) {
        this.decoderClass = decoderClass;
    }

    public Class<? extends TransportSelector> getSelectorClass() {
        return selectorClass;
    }

    public void setSelectorClass(Class<? extends TransportSelector> selectorClass) {
        this.selectorClass = selectorClass;
    }

    public int getPort() {
        return this.port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public Map<String, List<TransportClient>> getServers() {
        return servers;
    }

    public void setServers(Map<String, List<TransportClient>> servers) {
        this.servers = servers;
    }

    public int getConnectCount() {
        return connectCount;
    }

    public void setConnectCount(int connectCount) {
        this.connectCount = connectCount;
    }

    public Boolean getStartBySpring() {
        return startBySpring;
    }

    public void setStartBySpring(Boolean startBySpring) {
        this.startBySpring = startBySpring;
    }

    public int getProtocolType() {
        return protocolType;
    }

    public void setProtocolType(int protocolType) {
        this.protocolType = protocolType;
    }
}
